<?php
// 应用公共文件

// 获取分页数据信息
function getPageData()
{
    $pageData['page'] = input('page');
    $pageData['limit'] = input('limit');
    $pageData['start'] = ($pageData['page'] - 1) * $pageData['limit'];

    return $pageData;
}
//返回响应数据
function htSuccessReturn($msg, $data = [])
{
    $responseData['meta'] = ['code' => 1, 'msg' => $msg];
    if (!empty($data)) {
        $responseData['data'] = $data;
    }

    return json($responseData);
}
function htErrorReturn($msg, $code = 0,$data=[])
{
    $responseData['meta'] = ['code' => $code, 'msg' => $msg];
    if (!empty($data)) {
        $responseData['data'] = $data;
    }

    return json($responseData);
}
//获取排序字符串
function getOrderString()
{
    $requestData = input();
    $orderStr = '';
    if (isset($requestData['sort_field']) && !empty($requestData['sort_field'])) {
        if ($requestData['sort_type'] == 'descending') {
            $orderType = 'desc';
        } else {
            $orderType = 'asc';
        }
        $orderStr = $requestData['sort_field'].' '.$orderType.',';
    }

    return $orderStr;
}
// 删除目录或文件
function del_dir($dir)
{
    $dh = opendir($dir);
    while ($file = readdir($dh)) {
        if ($file != '.' && $file != '..') {
            $fullpath = $dir.'/'.$file;
            if (!is_dir($fullpath)) {
                @unlink($fullpath);
            } else {
                del_dir($fullpath);
            }
        }
    }
    closedir($dh);
    if (rmdir($dir)) {
        return true;
    } else {
        return false;
    }
}